<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;

use yii\bootstrap\Tabs;
$this->title = Yii::t('extensions', 'Extensions') . '-' . \Yii::t('extensions', 'Setting') . '-' . $model->name;
$powers = [
    '0.0' => '0.0',
    '0.1' => '0.1',
    '0.2' => '0.2',
    '0.3' => '0.3',
    '0.4' => '0.4',
    '0.5' => '0.5',
    '0.6' => '0.6',
    '0.7' => '0.7',
    '0.8' => '0.8',
    '0.9' => '0.9',
    '1.0' => '1.0',
];
$dailys = ['always'=>'總是',
        'hourly'=> '每小時',
        'daily'=> '每天',
        'weekly'=> '每周',
        'monthly'=> '每月',
        'yearly'=> '每年',
        'never'=> '從不'];
?>
<style type="text/css">
.postbox {
    min-width: 255px;
    border: 1px solid #e5e5e5;
    background: #fff;
}
.postbox>h3, .postbox h2, .postbox h3.hndle {
    font-size: 14px;
    padding: 8px 12px;
    margin: 0;
    line-height: 1.4;border-bottom: 1px solid #eee;
}

.inside {
    margin: 12px !important;
}
ul {
    margin: 6px 0 12px 0;
    list-style: none;
    padding: 0px;
}
.inside ul {
    margin: 6px 0 12px 0;
    list-style: none;
    padding: 0px;
}
dd, li {
    margin-bottom: 6px;
}
.postbox select {
    padding: 2px;
    line-height: 28px;
    height: 28px;
}
.alternate, .striped>tbody>:nth-child(odd), ul.striped>:nth-child(odd) {
    background-color: #f9f9f9;
}
.inside input {
    padding: 1px;
    margin: 0;
}
</style>
<div class="ext-form">
    <?php $form = ActiveForm::begin(); ?>
    <div class="page-title">
        <div class="title_left">
            <h2><?= Html::encode($this->title) ?></h2>
        </div>
        <div class="title_right">
            <div class="form-group pull-right"> 
                <?= Html::submitButton('<i class="glyphicon glyphicon-floppy-disk"></i>', ['class' =>'btn btn-primary']) ?>
                <?= Html::a('<i class="fa fa-mail-reply"></i>', ['/frontendmodule/default', 'type'=>$model->type], ['class'=>'btn btn-default'])?>
            </div>
        </div>
    </div>
    <div class="clear"></div>

    <?php echo Html::hiddenInput('urlReferrer',!empty($list['urlReferrer']) ? $list['urlReferrer'] : null);?>
    
    <div id="sm_priorities" class="sm-padded  postbox ">
        <h3 class="hndle"><span>优先权</span></h3>
        <div class="inside">
            <ul>
                <li>
                    <label for="sm_pr_home">
                        <?=Html::dropDownList('home', isset($formModels['home']) ? $formModels['home'] : '', $powers) ?>
                    首页                              </label>
                </li>
                <li>
                    <label for="sm_pr_posts">
                        <?=Html::dropDownList('newssingle', isset($formModels['newssingle']) ? $formModels['newssingle'] : '', $powers) ?>
                        news single
                    </label>
                </li>
                <li>
                    <label for="sm_pr_posts">
                        <?=Html::dropDownList('listsingle', isset($formModels['listsingle']) ? $formModels['listsingle'] : '', $powers) ?>
                        list single
                    </label>
                </li>
                <li>
                    <label for="sm_pr_posts">
                        <?=Html::dropDownList('media', isset($formModels['media']) ? $formModels['media'] : '', $powers) ?>
                        media
                    </label>
                </li>
                <li>
                    <label for="sm_pr_posts">
                        <?=Html::dropDownList('blogsingle', isset($formModels['blogsingle']) ? $formModels['blogsingle'] : '', $powers) ?>
                        blog single
                    </label>
                </li>
                <li>
                    <label for="sm_pr_posts">
                        <?=Html::dropDownList('wiki', isset($formModels['wiki']) ? $formModels['wiki'] : '', $powers) ?>
                        wiki single
                    </label>
                </li>
                
            </ul>

        </div>
    </div>

    <div id="sm_pages" class="postbox">
        <h3 class="hndle"><span>Additional Pages</span></h3>
        <div class="inside">

            Here you can specify files or URLs which should be included in the sitemap, but do not belong to your Site/WordPress.<br>For example, if your domain is www.foo.com and your site is located on www.foo.com/site you might want to include your homepage at www.foo.com<ul><li><strong>注意</strong>: If your site is in a subdirectory and you want to add pages which are NOT in the site directory or beneath, you MUST place your sitemap file in the root directory (Look at the "Location of your sitemap file" section on this page)!</li><li><strong>这个页面的 URL</strong>: 输入这个页面的地址，比如：http://dupola.com/dreamhost 或 https://twitter.com/dupola 或 http://caodan.net</li><li><strong>优先</strong>: 选择该页面的相关页面的优先权。比如，你的主页应该拥有一个更高的优先权。</li><li><strong>最近更改</strong>: 输入最后更改的日期，格式为 YYYY-MM-DD (例如 2005-12-31) (可选的l).</li></ul>                     <script type="text/javascript">
                            //<![CDATA[

                            var changeFreqVals = ['always','hourly','daily','weekly','monthly','yearly','never'];
                            var changeFreqNames = [ '总是','每小时','每天','每周','每月','每月','从不'];
                            var priorities= [0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0];

                            var pages = [ {url:"", priority:0.0, changeFreq:"always", lastChanged:""} ];
                            //]]>
                        </script>
                        <table width="100%" cellpadding="3" cellspacing="3" id="sm_pageTable">
                            <tbody><tr>
                                <th scope="col">这个页面的 URL</th>
                                <th scope="col">优先</th>
                                <th scope="col">更改频率</th>
                                <th scope="col">最近更改</th>
                                <th scope="col">#</th>
                            </tr>
                            <?php
                            if( !empty($formModels['sm_pages_ur']) ){
                                foreach ($formModels['sm_pages_ur'] as $key => $val) {
                                    ?>
                                    <tr class="alternate">
                                        <td>
                                        <?=Html::textInput('sm_pages_ur[]', $val, ['style'=>'width: 95%;']) ?>
                                        </td>
                                        <td style="width: 150px;">
                                            <?=Html::dropDownList('sm_pages_pr[]', $formModels['sm_pages_pr'][$key], $powers, ['style'=>'width: 95%;']) ?>
                                        </td>
                                        <td style="width: 150px;">
                                            <?=Html::dropDownList('sm_pages_cf[]', $formModels['sm_pages_cf'][$key], $dailys, ['style'=>'width: 95%;']) ?>
                                        </td>
                                        <td style="width: 150px;"><input type="text" name="sm_pages_lm[]" style="width: 95%;"></td><td style="text-align: center; width: 5px;"><a href="javascript:void(0);" onclick="removeNode(this)">X</a></td>
                                        <?=Html::hiddenInput('sm_pages_mark[]', $formModels['sm_pages_mark'][$key], ['value'=>'true']) ?>
                                    </tr>
                                    <?php
                                }
                            }
                            ?>
                        </tbody>
                    </table>
                    <a href="javascript:void(0);" onclick="sm_addPage();">增加一个新的页面</a>
                </div>
            </div>  
            <?php ActiveForm::end(); ?>
        </div>
        <script type="text/javascript">
    /*
 
 $Id: sitemap.js 48032 2008-05-27 14:32:06Z arnee $

 */

 function sm_addPage(url,priority,changeFreq,lastChanged) {

    var table = document.getElementById('sm_pageTable').getElementsByTagName('TBODY')[0];
    var ce = function(ele) { return document.createElement(ele) };
    var tr = ce('TR');

    var td = ce('TD');
    var iUrl = ce('INPUT');
    iUrl.type="text";
    iUrl.style.width='95%';
    iUrl.name="sm_pages_ur[]";
    if(url) iUrl.value=url;
    td.appendChild(iUrl);
    tr.appendChild(td);
    
    td = ce('TD');
    td.style.width='150px';
    var iPrio = ce('SELECT');
    iPrio.style.width='95%';
    iPrio.name="sm_pages_pr[]";
    for(var i=0; i <priorities.length; i++) {
        var op = ce('OPTION');
        op.text = priorities[i];        
        op.value = priorities[i];
        try {
            iPrio.add(op, null); // standards compliant; doesn't work in IE
        } catch(ex) {
            iPrio.add(op); // IE only
        }
        if(priority && priority == op.value) {
            iPrio.selectedIndex = i;
        }
    }
    td.appendChild(iPrio);
    tr.appendChild(td);
    
    td = ce('TD');
    td.style.width='150px';
    var iFreq = ce('SELECT');
    iFreq.name="sm_pages_cf[]";
    iFreq.style.width='95%';
    for(var i=0; i<changeFreqVals.length; i++) {
        var op = ce('OPTION');
        op.text = changeFreqNames[i];       
        op.value = changeFreqVals[i];
        try {
            iFreq.add(op, null); // standards compliant; doesn't work in IE
        } catch(ex) {
            iFreq.add(op); // IE only
        }
        
        if(changeFreq && changeFreq == op.value) {
            iFreq.selectedIndex = i;
        }
    }
    td.appendChild(iFreq);
    tr.appendChild(td);
    
    var td = ce('TD');
    td.style.width='150px';
    var iChanged = ce('INPUT');
    iChanged.type="text";
    iChanged.name="sm_pages_lm[]";
    iChanged.style.width='95%';
    if(lastChanged) iChanged.value=lastChanged;
    td.appendChild(iChanged);
    tr.appendChild(td);
    
    var td = ce('TD');
    td.style.textAlign="center";
    td.style.width='5px';
    var iAction = ce('A');
    iAction.innerHTML = 'X';
    iAction.href="javascript:void(0);"
    iAction.onclick = function() { table.removeChild(tr); };
    td.appendChild(iAction);
    tr.appendChild(td);
    
    var mark = ce('INPUT');
    mark.type="hidden";
    mark.name="sm_pages_mark[]";
    mark.value="true";
    tr.appendChild(mark);
    
    
    var firstRow = table.getElementsByTagName('TR')[1];
    if(firstRow) {
        var firstCol = (firstRow.childNodes[1]?firstRow.childNodes[1]:firstRow.childNodes[0]);
        if(firstCol.colSpan>1) {
            firstRow.parentNode.removeChild(firstRow);
        }
    }
    var cnt = table.getElementsByTagName('TR').length;
    if(cnt%2) tr.className="alternate";
    
    table.appendChild(tr);                                      
}

function sm_loadPages() {
    for(var i=0; i<pages.length; i++) {
        sm_addPage(pages[i].url,pages[i].priority,pages[i].changeFreq,pages[i].lastChanged);
    }
}
function removeNode($obj){
    $obj.parentNode.parentNode.remove();
}
</script>

<?php $this->registerJsFile(Yii::getAlias('@web')."/web/js/jq.insertimg.js", ['position'=>\yii\web\View::POS_END,'depends'=> [yii\web\JqueryAsset::className()]]); ?>
